package com.globaldom.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.globaldom.utils.Constants;
import com.globaldom.utils.MemCacheManager;
import com.globaldom.utils.Notifications;
import com.globaldom.utils.SessionManager;

@Controller
@RequestMapping(value = "/getallnotices")
public class NotificationGetAllController {
	public NotificationGetAllController() {
	}

	@RequestMapping(value = "/getall", method = RequestMethod.GET)
	public @ResponseBody
	Map<String, Object> getAllNotices(HttpSession session,HttpServletRequest request) {

		Map<String, Object> map = new HashMap<String, Object>();
		
		String personID = SessionManager.getID(request, session);
		if(null==personID) 
			{
			map.put(Constants.STATUS, "-ER");
			map.put(Constants.CODE, "401");
			return map;
			}
		
		List<Notifications> list = MemCacheManager.getNotifications(personID);
		if (null == list)
			list = new ArrayList<Notifications>();

		MemCacheManager.removeNotification(personID);

		map.put("notices", list);

		return map;
	}

}
